
#coding:utf-8    
#未来将使用 域名+独立IP 发送 11万封邮件，得到 1万的转化率  5%
#每天发2000封邮件   双数
#SMTP是发送邮件的协议，Python内置对SMTP的支持，可以发送纯文本邮件、HTML邮件以及带附件的邮件。
#Python对SMTP支持有smtplib和email两个模块，email负责构造邮件，smtplib负责发送邮件。


import smtplib  
import email.utils
from   email.mime.multipart import MIMEMultipart
from   email.mime.text import MIMEText
import csv
import hashlib
import time

# Replace sender@example.com with your "From" address. 
# This address must be verified.
SENDER     = 'taotao@coin2world.com'     #要改XXXXXXXXXXXXXXX
SENDERNAME = 'Coin2World'
# Replace recipient@example.com with a "To" address. If your account 
# is still in the sandbox, this address must be verified.

# Replace smtp_username with your Amazon SES SMTP user name.
USERNAME_SMTP = "AKIAJLAW5DPLB7UUGGJA" #要改XXXXXXXXXXXXXXX

# Replace smtp_password with your Amazon SES SMTP password.
PASSWORD_SMTP = "Ao7K1VSFv9YEPLndKd9+gVs7e5A5LYaZLFDcwCGXzxuv"  #要改XXXXXXXXXXXXXXX

# (Optional) the name of a configuration set to use for this message.
# If you comment out this line, you also need to remove or comment out
# the "X-SES-CONFIGURATION-SET:" header below.
#CONFIGURATION_SET = "ConfigSet"

# If you're using Amazon SES in an AWS Region other than US West (Oregon), 
# replace email-smtp.us-west-2.amazonaws.com with the Amazon SES SMTP  
# endpoint in the appropriate region.
HOST = "email-smtp.us-east-1.amazonaws.com"
PORT = 587


#读取CSV
filepath = '//Users//elsa//Desktop//proj//python//jd_maotai//learning_notebook-master//qqemail//splitdata//split_1.csv'

csv_reader = csv.reader(open(filepath, encoding='utf-8'))

for row in csv_reader:
    #date|  name  |qq  
    rowarray =  len(row)  
    rowdate = row[1]
    
    if rowarray>3 and rowdate!='datetime' :
        
        rowname = row[2]
        rowqq = row[3]+'@qq.com'
        
        print(rowdate,rowname,rowqq)
          
        RECIPIENT  = rowqq
        
        # The subject line of the email.
        SUBJECT = rowname+" 百-万-比_特-币大赠送、亚洲最大的场-外-交-易平台"

        # The email body for recipients with non-HTML email clients.
        BODY_TEXT = ("")

  
        BODY_HTML = " <p>  \
<span style='background-color:;'></span> \
</p> \
<h1 style='text-align:center;font-size:41px;font-family:Raleway, &quot;color:white;background-color:#2C3E50;'> \
	<span style='color:aqua;'>Coin</span>2<span style='color:coral;'>World</span> \
</h1> \
<span style='font-family:Helvetica, &quot;'></span> \
<p style='font-family:Helvetica, &quot;font-size:14px;'> \
	&nbsp; <span style='font-size:14px;'>您好： " + rowname
    
        BODY_HTML = BODY_HTML + "</span> </p> \
<p style='font-family:Helvetica, &quot;font-size:14px;'> \
	<span style='font-size:14px;'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style='font-size:14px;'>Coin2World总部位于国际金-融中心新加坡，<span style='color:#009900;font-size:16px;'><strong>正规交易牌照</strong></span>，由专业的国际化团队研发与运营，专注于为全球用户提供安全、便捷的比-特-币场-外-交-易服务。</span>  \
</p> \
<p style='font-family:Helvetica, &quot;font-size:14px;'> \
	<span style='font-size:14px;'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 活动期间，</span><em><strong><span style='font-size:16px;color:#009900;'>价值百-万-比_特-币大放送</span></strong></em><span style='font-size:14px;'><em><span style='font-size:14px;'>，</span></em><span style='font-size:14px;'>注-册就送比-特-币，先到先得。</span></span> \
</p> \
<p style='font-family:Helvetica, &quot;font-size:14px;'> \
	<span style='font-size:14px;'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 注-册地址:&nbsp; &nbsp; &nbsp; <span style='color:#337FE5;'>https://www.coin2world.com/register.html</span></span>  \
</p> \
<p style='font-family:Helvetica, &quot;font-size:14px;'> \
	<span style='font-size:14px;'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style='font-size:16px;'>&nbsp;</span></span><strong><span style='font-size:16px;color:#009900;'>邀-请好友注-册、交-易-费全返、多邀-请多返-俑</span></strong>  \
</p> \
<p style='font-family:Helvetica, &quot;font-size:14px;'> \
	<span style='font-size:14px;'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 现在就邀-请：<span style='color:#337FE5;'>https://www.coin2world.com/invite.html</span></span>  \
</p> \
<p style='font-family:Helvetica, &quot;font-size:14px;'> \
	<span style='font-size:14px;'>&nbsp;</span>  \
</p> \
<p style='font-family:Helvetica, &quot;font-size:14px;'> \
	<span style='font-size:14px;'>&nbsp;Coin2World Team</span>  </p> <p> <br /> </p>"


        hash_html  = hashlib.sha256()
        hash_html.update(BODY_HTML.encode('utf-8'))
        BODY_HTML  = BODY_HTML + hash_html.hexdigest()
   
        # Create message container - the correct MIME type is multipart/alternative.
        msg = MIMEMultipart('alternative')
        msg['Subject'] = SUBJECT
        msg['From'] = email.utils.formataddr((SENDERNAME, SENDER))
        msg['To'] = RECIPIENT
        # Comment or delete the next line if you are not using a configuration set
        #msg.add_header('X-SES-CONFIGURATION-SET',CONFIGURATION_SET)

        # Record the MIME types of both parts - text/plain and text/html.
        part1 = MIMEText(BODY_TEXT, 'plain')
        part2 = MIMEText(BODY_HTML, 'html')

        # Attach parts into message container.
        # According to RFC 2046, the last part of a multipart message, in this case
        # the HTML message, is best and preferred.
        msg.attach(part1)
        msg.attach(part2)

        # Try to send the message.
        try:  
            server = smtplib.SMTP(HOST, PORT)
            server.ehlo()
            server.starttls()
            #stmplib docs recommend calling ehlo() before & after starttls()
            server.ehlo()
            server.login(USERNAME_SMTP, PASSWORD_SMTP)
            server.sendmail(SENDER, RECIPIENT, msg.as_string())
            server.close()
        # Display an error message if something goes wrong.
        except Exception as e:
            print ("Error: ", e)
        else:
            print ("Email Sent ",rowqq)
        
        time.sleep(1)
        
        
      


